kancollefandomcom_vi-20200214-history
Mô đun:NanaminFunctions
local Ship = require("Module:Ship") local NanaminFunctions = {} function NanaminFunctions.split(haystack, needle) local result = {} while mw.ustring.find(haystack, needle) do local split = mw.ustring.find(haystack, needle) table.insert(result, mw.ustring.sub(haystack, 1, split - 1)) haystack = mw.ustring.sub(haystack, split + 1) end table.insert(result, haystack) return result end function NanaminFunctions.add_to_fighter_power(current_fp, equip, planes) --Only fighter planes, dive bombers, torpedo bombers and seaplane bombers with an AA stat are counted local types_allowed = { 6 = true, 7 = true, 8 = true, 11 = true } if types_allowedequip:type() and equip:aa() then current_fp = current_fp + math.floor(math.sqrt(planes) * equip:aa()) end return current_fp end function NanaminFunctions.add_to_elos_ship(current_elos, entry, use_los) if entry3 nil then return current_elos end local ship = Ship(entry1, entry2) local los = ship:los() or 0 local los_max = ship:los_max() or los if use_los then los = tonumber(entry3) else los = math.floor(los + ((los_max - los) * tonumber(entry3) / 99)) end return current_elos + math.sqrt(los) * 1.69 end function NanaminFunctions.add_to_elos(current_elos, equip) --Effective LoS = Dive Bomber LoS x (1.04) + Torpedo Bomber LoS x (1.37) + Carrier-based Recon Plane LoS x (1.66) + Recon Seaplane LoS x (2.00) + Seaplane Bomber LoS x (1.78) + Small Radar LoS x (1.00) + Large Radar LoS x (0.99) + Searchlight LoS x (0.91) + √(base LoS of each ship) * (1.69) + (HQ Lv. rounded up to the next multiple of 5) x (-0.61)-- local multiplier = { 7 = 1.04, 8 = 1.04, 9 = 1.66, 10 = 2.00, 11 = 1.78, 12 = 1.00, 13 = 0.99, 29 = 0.91 } if multiplierequip:type() ~= nil and equip:los() then current_elos = current_elos + (equip:los() * multiplierequip:type()) end return current_elos end function NanaminFunctions.get_hq_bracket(hq_level) local bracket = tonumber(hq_level or 0) --Get bracket of 5 bracket = bracket - (bracket % 5) + 5 if tonumber(hq_level or 0) % 5 0 then bracket = bracket + 5 end return bracket end function NanaminFunctions.process_legacy_name(name) local names = { Naval Gun" = "12cm Single Gun Mount", Naval Gun" = "12.7cm Single Gun Mount", Naval Gun" = "14cm Single Gun Mount", Triple Gun Mount (Main)" = "15.5cm Triple Gun Mount", Twin Gun Mount" = "20.3cm (No.2) Twin Gun Mount", Twin Gun Mount" = "20.3cm (No.3) Twin Gun Mount", 20.3cm Twin Cannon" = "SKC34 20.3cm Twin Gun Mount", 41cm Triple Cannon" = "Prototype 41cm Triple Gun Mount", 51cm Twin Cannon" = "Prototype 51cm Twin Gun Mount", Naval Gun" = "15.2cm Single Gun Mount", Triple Gun Mount (Secondary)" = "15.5cm Triple Secondary Gun Mount", Twin Gun Mount" = "15cm Twin Secondary Gun Mount", Twin High-angle Mount" = "8cm High-angle Gun", Twin High-angle Mount" = "10cm Twin High-angle Gun Mount", Twin High-angle Gun Mount (Carriage)" = "10cm Twin High-angle Carriage Mount", Twin High-angle Mount + Anti-Aircraft Fire Director" = "10cm Twin High-angle Gun Mount + Anti-Aircraft Fire Director", High-angle Mount" = "12.7cm Single High-angle Gun Mount", Twin High-angle Mount" = "12.7cm Twin High-angle Gun Mount", Twin High-angle Mount (Late Model)" = "12.7cm Twin High-angle Gun Mount (Late Model)", Twin High-angle Mount + Anti-Aircraft Fire Director" = "12.7cm High-angle Gun + Anti-Aircraft Fire Director", Machine Gun" = "12.7mm Single Machine Gun Mount", Autocannon" = "25mm Single Autocannon Mount", 40mm Twin Machine Gun" = "Type Bi 40mm Twin Autocannon Mount", Quad Torpedo Mount" = "61cm Quadruple Torpedo Mount", Quad Oxygen Torpedo Mount" = "61cm Quadruple (Oxygen) Torpedo Mount", Quint Oxygen Torpedo Mount" = "61cm Quintuple (Oxygen) Torpedo Mount", Hull-mount O2 Torpedoes" = "53cm Bow (Oxygen) Torpedo Mount", Submarine Bow Torpedo Mount (8 tubes)" = "Submarine 53cm Bow Torpedo Mount (8 tubes)", A Ko-hyoteki" = "Kouhyouteki", 21 Zero Fighter" = "Type 0 Fighter Model 21", 21 Zero Fighter (Skilled)" = "Type 0 Fighter Model 21 (Skilled)", 52 Zero Fighter" = "Type 0 Fighter Model 52", Fighter Type 52 Type C (601 Air Group)" = "Zero Fighter Model 52C (601 Air Group)", Kai 2" = "Shiden Kai Ni", 62 Zero Fighter-bomber" = "Type 0 Fighter Model 62 (Fighter-bomber)", 2 Recon Aircraft" = "Type 2 Reconnaissance Aircraft", 0 Recon Seaplane" = "Type 0 Reconnaissance Seaplane", 98 Recon Seaplane (Night Recon)" = "Type 98 Reconnaissance Seaplane (Night Recon)", Observation Autogyro" = "No. Ka Observation Autogyro", 3 Spotter/Liaison (ASW)" = "Type 3 Command Liaison Aircraft (ASW)", 22 Surface RADAR Kai 4" = "No. 22 Surface Radar Kai Yon", 13 AIR RADAR Kai" = "No. 13 Air Radar Kai", 21 Air RADAR Kai" = "No. 21 Air Radar Kai", 93 Passive SONAR" = "Type 93 Passive Sonar", 3 SONAR" = "Type 3 Active Sonar", 0 Passive SONAR" = "Type 0 Passive Sonar", 94 Depth Charge" = "Type 94 Depth Charge Projector", 3 Depth Charge" = "Type 3 Depth Charge Projector", 91 Armor-Piercing (AP) Shell" = "Type 91 Armor Piercing Shell", 1 Armor-Piercing (AP) Shell" = "Type 1 Armor Piercing Shell", Steam Turbine" = "Improved Kanhon Type Turbine", Steam Boiler" = "Enhanced Kanhon Type Boiler", High Pressure-Temperature Steam Boiler" = "New Model High Temperature High Pressure Boiler", Bulge (Medium)" = "Extension Bulge (Medium)", Bulge (Large)" = "Extension Bulge (Large)", Canister" = "Drum Canister (Transport Use)", } --Radar/sonar names without any special pieces name = name:gsub("^Type%s(.+)%sRADAR$", "No. %1 Radar") name = namesname or name return name end return NanaminFunctions